<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银行系统 - 贷款详情</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.header {
    background-color: #333;
    color: white;
    padding: 20px;
    text-align: center;
}

.navbar {
    background-color: #444;
    overflow: hidden;
}

.navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.navbar a:hover {
    background-color: #555;
}

.navbar a.active {
    background-color: #555;
}

.content {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.loan-detail {
    background-color: #f9f9f9;
    padding: 20px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.detail-section {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid #ddd;
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-label {
    font-weight: bold;
    width: 150px;
    display: inline-block;
}

.approval-form {
    background-color: #f1f1f1;
    padding: 15px;
    border-radius: 4px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input[type="radio"] {
    margin-right: 5px;
}

.form-group textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
    height: 100px;
}

button {
    background-color: #4CAF50;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 10px;
}

button:hover {
    background-color: #45a049;
}

.back-btn {
    background-color: #f44336;
}

.back-btn:hover {
    background-color: #d32f2f;
}

.status-pending { color: #FF9800; }
.status-approved { color: #4CAF50; }
.status-rejected { color: #F44336; }
.status-paid { color: #2196F3; }

.error-message {
    color: #F44336;
    margin: 10px 0;
    padding: 10px;
    background-color: #ffcccc;
    border-radius: 4px;
}
</style>
</head>
<body>
    <div class="header">
        <h1>银行管理系统 - 贷款详情</h1>
        <p>欢迎您，<c:out value="${sessionScope.user.username}" /></p>
    </div>
    
    <div class="navbar">
       <a href="totalUser">首页</a>
        <a href="adminLoanApplications" class="active">贷款审批</a>
		<a href="adminLoanHistory.jsp">贷款审批</a>
        <a href="account">账户管理</a>
        <a href="logout">退出登录</a>
    </div>
    
    <div class="content">
        <h2>贷款详情</h2>
        
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>
        
        <c:if test="${empty loan}">
            <p>贷款信息不存在</p>
            <a href="adminLoanApplications" class="back-btn">返回</a>
        </c:if>
        
        <c:if test="${not empty loan}">
            <div class="loan-detail">
                <div class="detail-section">
                
                    <h3>基本信息</h3>
                    <p><span class="detail-label">贷款编号:</span> ${loan.loan_number}</p>
                    <p><span class="detail-label">申请金额:</span> ${loan.amount}</p>
                    <p><span class="detail-label">剩余金额:</span> ${loan.remaining_amount}</p>
                    <p><span class="detail-label">申请时间:</span> ${loan.create_time}</p>
                    <p><span class="detail-label">到期日:</span> ${loan.due_date}</p>
                    <p><span class="detail-label">当前状态:</span> 
                        <span class="${loan.statusClass}">${loan.statusDesc}</span>
                    </p>
                 
                </div>
                
                <div class="detail-section">
                    <h3>申请人信息</h3>
                    <p><span class="detail-label">姓名:</span> ${loan.user.real_name}</p>
                    <p><span class="detail-label">身份证号:</span> ${loan.user.id_card}</p>
                    <p><span class="detail-label">手机号:</span> ${loan.user.phone}</p>
                </div>
                
                <c:if test="${loan.status == 1 && not empty loan}">
                    <div class="approval-form">
                        <h3>审批操作</h3>
                        <form action="${pageContext.request.contextPath}/approveLoan" method="post">
                            <input type="hidden" name="loanId" value="${loan.id}">
                            
                            <div class="form-group">
                                <label>审批结果</label><br>
                                <input type="radio" id="approve" name="action" value="approve" required>
                                <label for="approve">批准</label>
                                <input type="radio" id="reject" name="action" value="reject">
                                <label for="reject">拒绝</label>
                            </div>
                            
                            <div class="form-group" id="rejectReasonGroup" style="display: none;">
                                <label for="rejectReason">拒绝原因</label>
                                <textarea id="rejectReason" name="reason" rows="3"></textarea>
                            </div>
                            
                            <button type="submit">提交审批</button>
                            <button type="button" onclick="history.back()">返回</button>
                        </form>
                    </div>
                </c:if>
                
                <c:if test="${loan.status != 1}">
                    <div class="form-group">
                        <button type="button" onclick="history.back()">返回</button>
                    </div>
                </c:if>
            </div>
        </c:if>
    </div>
    
    <script>
        // 显示/隐藏拒绝原因输入框
        document.getElementById('reject').addEventListener('change', function() {
            document.getElementById('rejectReasonGroup').style.display = 
                this.checked ? 'block' : 'none';
        });
    </script>
</body>
</html>